package com.cheyun.netsalev3.repository

import com.cheyun.netsalev3.bean.StockDetailsParam
import com.cheyun.netsalev3.utils.api.ApiCallback
import com.cheyun.netsalev3.utils.api.ApiClient
import com.cheyun.netsalev3.utils.api.ApiException
import com.cheyun.netsalev3.utils.api.BaseResp
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
import kotlin.reflect.KFunction1

class StockDetailsRepository(var id: Int) {
    /**
     * 获取库存
     */
    fun getStock(kFunction1: KFunction1<@ParameterName(name = "item") StockDetailsParam, Unit>) {
        ApiClient.getInstance().getStock(id)
                .subscribeOn(Schedulers.io())
                .subscribeOn(AndroidSchedulers.mainThread())
                .subscribe(object : ApiCallback<BaseResp<StockDetailsParam>>() {
                    override fun onSuccess(t: BaseResp<StockDetailsParam>) {
                        t.data?.apply(kFunction1)
                    }

                    override fun onError(ex: ApiException) {

                    }


                })
    }
}